<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2017/10/27
  Time: 18:01
  To change this template use File | Settings | File Templates.
--%>
<!--
步骤：
1.获取当前页面所有的a节点，并且为每一个a节点都添加onclick响应函数，同时取消其默认行为
2.准备发送Ajax请求：url（a节点的href属性值）；args(时间戳)
3.响应为一个json对象io。，包括：bookName,totalBookNumber,totalMoney
4.把对应的属性添加到对应的位置
-->
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function () {
            var isHasCart = ${sessionScope.shoppingCart==null};
            console.log(true == isHasCart);
            if (true == isHasCart) {
                $("#cartststus").hide();
            } else {
                $("#cartststus").show();
                var t = "${sessionScope.shoppingCart.bookName}";
                $("#bookName").text(t);
                $("#totolBookNumber").text(${sessionScope.shoppingCart.getTotalBookNumer()});
                $("#totalMoney").text(${sessionScope.shoppingCart.getTotalMoney()});
            }
            $("a").click(function () {
                console.log(true == isHasCart);
                $("#cartststus").show();
                var url = this.href;
                alert(url);
                var args = {"time": 1};
                $.getJSON(url, args, function (data) {
                    $("#bookName").text(data.bookName);
                    $("#totolBookNumber").text(data.totalBookNumber);
                    $("#totalMoney").text(data.totalMoney);
                    console.log(data);
                });
                return false;
            });
        })
    </script>
</head>
<body>
<div id="cartststus">您已将&nbsp;<span id="bookName"></span>&nbsp;加入到购物车中，
    购物车中的书有&nbsp; <span id="totolBookNumber"></span>&nbsp;本
    总价格&nbsp;<span id="totalMoney"></span>&nbsp;元。
</div>
<br><br>
Java&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/addToCart?id=Java&price=100">加入购物车</a><br><br>
Oracle&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/addToCart?id=Oracleracle&price=200">加入购物车</a><br><br>
Struct2&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/addToCart?id=Struct2&price=300">加入购物车</a><br>
</body>
</html>
